////
////  RestHelper.m
////  PostMessa
////
////  Created by never down on 15-5-12.
////  Copyright (c) 2015年 ygy_ios. All rights reserved.
////
//
//#import <Foundation/Foundation.h>
//
//#import "RESTHelper.h"
////#import "Log.h"
//
//static NSString * const BOUNDRY = @"--------------------------7d71a819230404";
//
////分类private
//@interface RESTHelper(Private)
//
//@end
////分类结束
//
//@implementation  RESTHelper(Private)
//
//- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
//{
//    NSLog(@"NSURLCOnnection ERROR!");
//    [mdelegate performSelector: errorSelector  withObject:error];
//    
//    //NSData *returnData = [NSURLConnection sendAsynchronousRequest:<#(NSURLRequest *)#> queue:<#(NSOperationQueue *)#> completionHandler:<#^(NSURLResponse *response, NSData *data, NSError *connectionError)handler#>];
//    NSData *returnData = [NSURLConnection sendSynchronousRequest:nil
//                                               returningResponse:nil
//                                                           error:nil];
//    
//
//}
//
//- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
//{
//    NSLog(@"NSURLConnection ReceivedData!");
//    NSString *reply  =[ [NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] ;
//    [mdelegate performSelector:  doneSelector  withObject: reply];
//}
//@end
//
//@implementation RESTHelper
//
//-(id)initWithUrl:(NSString*)urlPath postData:(NSDictionary*)data delegate:(id)aDeletgate onErrorCallback:(SEL)errorCallback onCompletedCallback:(SEL)complectedCallback
//{
//    if (self=[super init])
//    {
//        requestUrlPath =[[NSString stringWithString:  urlPath] lowercaseString];
//        mdelegate=[aDeletgate retain];
//        errorSelector= errorCallback;
//        doneSelector = complectedCallback;
//        NSURL  * url=[NSURL URLWithString:requestUrlPath];
//        NSMutableURLRequest  * req=[NSMutableURLRequest requestWithURL: url];
//        if (data != nil )
//        {
//            [req setHTTPMethod:@"POST"];
//            [reqsetValue: [NSString stringWithFormat:@"multipart/form-data; boundary=%@", BOUNDRY] forHTTPHeaderField:@"Content-Type"];
//            int len=512;
//            NSMutableData  * postData =[NSMutableData dataWithCapacity:len];
//            [postData  appendData: [[NSString  stringWithFormat:@"--%@/r/n",BOUNDRY] dataUsingEncoding:NSUTF8StringEncoding]];
//            int  i=0;
//            int  cnt=data.count;
//            for ( NSString * key in  [data allKeys])
//            {
//                [postData  appendData: [[NSString stringWithFormat:@"Content-Disposition: form-data; name=/"%@/"/r/n/r/n", key ] dataUsingEncoding:NSUTF8StringEncoding]];
//                [postData  appendData: [[NSString  stringWithFormat:@"%@",[data objectForKey:key ]] dataUsingEncoding:NSUTF8StringEncoding]];
//                if( i != cnt -1  )
//                {
//                    [postData  appendData: [[NSString  stringWithFormat:@"/r/n--%@/r/n",BOUNDRY] dataUsingEncoding:NSUTF8StringEncoding]];
//                }
//                i++ ;
//            }
//            [postData  appendData:[[NSString stringWithFormat:@"/r/n--%@--/r/n",BOUNDRY] dataUsingEncoding:NSUTF8StringEncoding]];
//            [req  setHTTPBody:postData];
//        }
//        else
//        {
//            [req  setHTTPMethod:@"GET"];
//        }
//        NSURLConnection * connection =[[NSURLConnection alloc] initWithRequest:req delegate:self] ;
//        if(!connection)
//        {
//            NSDictionary * errorInfo=[NSDictionary dictionaryWithObjectsAndKeys:@"发送请求失败" ,@"errorKey", nil];
//            NSError * error=[NSError errorWithDomain:@"www.mainaer.com" code:100 userInfo:  errorInfo];
//            [mdelegate performSelector:errorCallback withObject: error];
//        }
//        else
//        {
//            NSLog(@"Send Data Request /n");
//        }
//    }
//    return self;
//}
//
//- (void)dealloc
//{
//    //[mdelegate release];
//    mdelegate = nil;
//    
//    doneSelector = NULL;
//    errorSelector = NULL;
//    
//    //[super dealloc];
//}
//
//@end